#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=6e6+5,INF=1e9;
int n,m,k,sx,sy,tx,ty,ans=INF;
string S[N];
deque<pair<int,int>>Q;
vector<vector<int>>fdx,fdy;
inline int findx(const int&y,const int&x){return fdx[y][x]==x?x:fdx[y][x]=findx(y,fdx[y][x]);}
inline int findy(const int&x,const int&y){return fdy[x][y]==y?y:fdy[x][y]=findy(x,fdy[x][y]);}
inline void del(const int&x,const int&y){fdy[x][y]=y+1,fdx[y][x]=x+1;}
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	freopen("stamp.in","r",stdin);
	freopen("stamp.out","w",stdout);
	cin>>n>>m>>k>>sx>>sy>>tx>>ty,--sx,--sy,--tx,--ty;
	for(int i=0;i<n;++i)cin>>S[i];
	vector<vector<int>>D(n,vector<int>(m,INF));
	fdx.resize(m),fdy.resize(n);
	for(auto&v:fdx)v.resize(n+1),iota(v.begin(),v.end(),0);
	for(auto&v:fdy)v.resize(m+1),iota(v.begin(),v.end(),0);
	Q.emplace_back(sx,sy),D[sx][sy]=0;
	while(!Q.empty()){
		const auto [x,y]=Q.front();Q.pop_front();
		if(x==tx&&y==ty)ans=min(ans,D[x][y]);
		if(min(abs(x-tx),abs(y-ty))<k&&max(abs(x-tx),abs(y-ty))<=k)ans=min(ans,D[x][y]+1);
		if(x>0&&S[x-1][y]=='.'&&D[x-1][y]>D[x][y])D[x-1][y]=D[x][y],Q.emplace_front(x-1,y);
		if(x<n-1&&S[x+1][y]=='.'&&D[x+1][y]>D[x][y])D[x+1][y]=D[x][y],Q.emplace_front(x+1,y);
		if(y>0&&S[x][y-1]=='.'&&D[x][y-1]>D[x][y])D[x][y-1]=D[x][y],Q.emplace_front(x,y-1);
		if(y<m-1&&S[x][y+1]=='.'&&D[x][y+1]>D[x][y])D[x][y+1]=D[x][y],Q.emplace_front(x,y+1);
		if(x-k>=0){
			int l=max(0,y-k+1),r=min(m-1,y+k-1);
			for(int i=findy(x-k,l);i<=r;i=findy(x-k,i)){
				if(D[x-k][i]>D[x][y]+1)D[x-k][i]=D[x][y]+1,Q.emplace_back(x-k,i);
				del(x-k,i);
			}
		}
		if(x+k<n){
			int l=max(0,y-k+1),r=min(m-1,y+k-1);
			for(int i=findy(x+k,l);i<=r;i=findy(x+k,i)){
				if(D[x+k][i]>D[x][y]+1)D[x+k][i]=D[x][y]+1,Q.emplace_back(x+k,i);
				del(x+k,i);
			}
		}
		if(y-k>=0){
			int l=max(0,x-k+1),r=min(n-1,x+k-1);
			for(int i=findx(y-k,l);i<=r;i=findx(y-k,i)){
				if(D[i][y-k]>D[x][y]+1)D[i][y-k]=D[x][y]+1,Q.emplace_back(i,y-k);
				del(i,y-k);
			}
		}
		if(y+k<m){
			int l=max(0,x-k+1),r=min(n-1,x+k-1);
			for(int i=findx(y+k,l);i<=r;i=findx(y+k,i)){
				if(D[i][y+k]>D[x][y]+1)D[i][y+k]=D[x][y]+1,Q.emplace_back(i,y+k);
				del(i,y+k);
			}
		}
	}
	return cout<<ans,0;
}
/*
*/